package app.tcp;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;

import app.ui.MainFrame;

public class PlayerClient {
	private Socket clientSocket = null;
	private ObjectOutputStream output = null;
	private ObjectInputStream input = null;
	private TCP_Utilities tcp_Utilities;

	public PlayerClient(MainFrame mFrame) {
		this.tcp_Utilities = new TCP_Utilities(mFrame);
	}

	public void closePlayerServer() throws IOException {
		clientSocket.close();
		output.close();
		input.close();
	}

	public TCP_Utilities getTcp_Utilities() {
		return tcp_Utilities;
	}

	public void connectToServer() {
		try {
			clientSocket = new Socket("localhost", 4444);
			this.output = new ObjectOutputStream(clientSocket.getOutputStream());
			this.input = new ObjectInputStream(clientSocket.getInputStream());
			this.tcp_Utilities.setInput(input);
			Thread t = new Thread(tcp_Utilities);
			t.start();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
